<template>
  <div>
    <f-search-form :more='true' @searchHandler='searchHandler'>
      <f-search-form-item label='单号' name='paymentNo' />
      <f-search-form-item label='业务员' name='saleManName' />
      <f-search-form-item label='结算日期' type='range' name='beginDate' />
    </f-search-form>
    <f-table ref='table' size='small' rowKey='paymentId' :showTotal='false' :showSetting='false' setting-key='payment1' :tableColumns='columns' :multiple='false' :operator='operator' :params='queryParam' :scroll='{x:true}' :api='api.payment' handler='hySettlePayMonitorHandler'>
      <span slot='paymentNo' slot-scope='text, record, index'>
         <span v-clipboard:copy='text' v-clipboard:success='onCopy' style='cursor:pointer'>{{ text }}</span>
      </span>
      <span slot='settleType' slot-scope='text, record, index'>
         <a-tag color='#87d068' v-if='text==1'>渠道商</a-tag>
         <a-tag color='#f47920' v-if='text==2'>商务经理</a-tag>
         <a-tag color='#8a5d19' v-if='text==3'>片区服务商</a-tag>
         <a-tag color='#7bbfea' v-if='text==4'>商务总负责人</a-tag>
      </span>
      <span slot='invoiceType' slot-scope='text, record, index'>
            <a-tag color='#87d068' v-if='text==1'>普票</a-tag>
            <a-tag color='#108ee9' v-if='text==2'>专票</a-tag>
       </span>
      <span slot='drugType' slot-scope='text, record, index'>
           <a-tag color='#2db7f5' v-if='text=="ZY"'>自营</a-tag>
           <a-tag color='#FF0000' v-if='text=="ZS"'>招商</a-tag>
       </span>
      <span slot='taskName' slot-scope='text, record, index'>
          <a-tag color='#FF6103' @click='processImg(record)'>{{ record.taskName }}</a-tag>
      </span>
      <span slot='action' slot-scope='text, record'>
         <template v-if='record.rowIndex=="合计"'>
           <span>合计</span>
         </template>
          <template v-if='record.rowIndex!="合计"'>
            <a href='javascript:;' @click="$refs['settleDetailsDrawer'].showDrawer(record)">查看</a>
            <a-divider type='vertical' />
          </template>
          <a-dropdown v-if='record.rowIndex!="合计"'>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
                <a-menu-item>
                <a href='javascript:;' @click='processImg(record)'>流程图</a>
              </a-menu-item>
       
              <a-menu-item v-if='superAdmin'>
                 <a href='javascript:;' @click='deleteProcessInstance(record.processInstanceId,"hySettlePayProcDeleteHandler")'>撤销审批</a>
              </a-menu-item>
                <a-menu-item v-if='!record.paymentId'>
                <a href='javascript:;' @click='deleteProcessInstance(record.processInstanceId)'>清理数据</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
    </f-table>
    <process-image ref='processImg' v-if='processImageVisible' :visible.sync='processImageVisible' :processInstanceId='processInstanceId'></process-image>
    <settle-details-drawer ref='settleDetailsDrawer' @success='onLoad'></settle-details-drawer>
    <print-modal ref='printModal'></print-modal>
    <invoice-pay-drawer ref='invoicePayDrawer' @success='onLoad'></invoice-pay-drawer>
  </div>
</template>
<script>

import api from "../../js/api"
import ProcessImage from "../../../flowable/process/process_image"
import SettleDetailsDrawer from "./components/settle_details_drawer"
import { processMixins } from "@/core/mixins/processMixins"
import InvoicePayDrawer from "@/views/module/haiying/tasktodo/payment/components/invoice/invoice_pay_drawer"

export default {
  name: "Tab2",
  mixins: [processMixins],
  components: {
    InvoicePayDrawer,
    ProcessImage,
    SettleDetailsDrawer
  },
  data() {
    let me = this
    //操作按钮
    let operator = []

    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {},
      processInstanceId: "",
      superAdmin: this.superAdmin,
      processImageVisible: false,
      // 表头
      columns: [
        {
          title: "序号",
          width: "60px",
          fixed: "left",
          align: "center",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "单号",
          align: "center",
          fixed: "left",
          dataIndex: "paymentNo",
          scopedSlots: { customRender: "paymentNo" }
        },
        {
          title: "结算范围",
          align: "center",
          width: "60px",
          dataIndex: "settleType",
          scopedSlots: { customRender: "settleType" }
        },
        {
          title: "部门",
          align: "left",
          sorter:true,
          width: "80px",
          dataIndex: "deptName"
        },
        {
          title: "业务员",
          align: "left",
          sorter:true,
          width: "80px",
          dataIndex: "saleManName"
        },
        {
          title: "业务编码",
          align: "left",
          sorter:true,
          width: "80px",
          dataIndex: "saleManBusinessNo"
        },
        {
          title: "申请金额",
          align: "center",
          dataIndex: "amount",
          width: "100px",
          needTotal: true
        },
        {
          title: "申请日期",
          align: "center",
          width: "100px",
          dataIndex: "amountDate"
        },
        {
          title: "收票单位",
          align: "left",
          width: "180px",
          ellipsis: true,
          dataIndex: "companyName"
        },
        {
          title: "开票单位",
          align: "left",
          ellipsis: true,
          width: "180px",
          dataIndex: "payeeName"
        },
        {
          title: "发票项目",
          align: "left",
          ellipsis: true,
          width: "100px",
          dataIndex: "title"
        },
        {
          title: "发票类型",
          align: "center",
          width: "80px",
          dataIndex: "invoiceType",
          scopedSlots: { customRender: "invoiceType" }
        },
        {
          title: "开票金额",
          align: "left",
          needTotal: true,
          width: "80px",
          type: 10,
          dataIndex: "invoiceAmount"
        },
        {
          title: "不含税金额",
          align: "left",
          width: "90px",
          type: 10,
          needTotal: true,
          dataIndex: "noTaxAmount"
        },
        {
          title: "税费",
          align: "left",
          width: "80px",
          needTotal: true,
          type: 10,
          dataIndex: "taxAmount"
        },
        {
          title: "3%开票金额",
          align: "left",
          needTotal: true,
          width: "100px",
          type: 10,
          dataIndex: "senondInvoiceAmount"
        },
        {
          title: "3%开票税金",
          align: "left",
          width: "100px",
          needTotal: true,
          type: 10,
          dataIndex: "secondTaxAmount"
        },
        {
          title: "创建日期",
          align: "center",
          width: "100px",
          dataIndex: "createTime"
        },
        {
          title: "申请人",
          align: "center",
          width: "100px",
          dataIndex: "nickName"
        },
        {
          title: "审批状态",
          align: "center",
          fixed: "right",
          dataIndex: "taskName",
          scopedSlots: { customRender: "taskName" }
        },
        {
          title: "操作",
          align: "center",
          dataIndex: "action",
          width: "160px",
          fixed: "right",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator
    }
  },
  created() {
  },
  methods: {
    onLoad() {
      this.$refs.table.refresh()
    },
    processImg(task) {
      this.processInstanceId = task.processInstanceId
      this.processImageVisible = true
    },
    /**
     * 查询事件
     * @param searchParams
     */
    searchTable(searchParams) {
      this.queryParam = Object.assign(this.queryParam, searchParams)
      this.$refs.table.refresh(true, searchParams)
    },
    invoiceApplyHandler(record) {
      this.$refs["invoiceApplyDrawer"].showDrawer({
        paymentId: record.paymentId
      })
    },
    /**
     * 下载服务协议
     * @param record
     */
    downloadFwxy(record) {
      let env = process.env.NODE_ENV
      let url = "bus/export/fwxy"
      if (env == "development") {
        url = "../../../base/bus/export/fwxy"
      }
      this.http.exportExcel(this, {
        url: url,
        data: {
          paymentId: record.paymentId
        },
        success: function(me, data) {
        }
      })
      this.visible = false
    },
    /**
     * 下载开票申请
     * @param record
     */
    downloadKpsq(record) {
      let env = process.env.NODE_ENV
      let url = "bus/export/kpsq"
      if (env == "development") {
        url = "../../../base/bus/export/kpsq"
      }
      this.http.exportExcel(this, {
        url: url,
        data: {
          paymentId: record.paymentId
        },
        success: function(me, data) {
        }
      })
      this.visible = false
    },
    printOrder(record) {
      this.$refs["printModal"].open(record.paymentId, 3, "Invoice")
    },
    unClaimTask(task) {
      this.http.put(this, {
        url: this.api.tasktodo.unclaim,
        data: {
          taskId: task.taskId
        },
        success(me, data) {

        }
      })
    }
  }
}
</script>
